import { RegisterComponent } from "@feng3d/ecs";
import { ArrayCamera } from "../../thirdparty/three/imports";
import { PerspectiveCamera3D } from "./PerspectiveCamera3D";

declare module "@feng3d/ecs"
{
    interface ComponentMap { ArrayCamera3D: ArrayCamera3D; }
}

/**
 * 包装`three`中`ArrayCamera`。
 */
@RegisterComponent({ name: 'ArrayCamera3D' })
export class ArrayCamera3D extends PerspectiveCamera3D
{
    /**
     * @private
     */
    _camera: ArrayCamera;

    get cameras()
    {
        return this._cameras;
    }

    set cameras(v)
    {
        this._cameras = v;
        if (this._camera)
        {
            const perspectiveCameras = this.cameras.map((v) => v._camera);
            this._camera.cameras = perspectiveCameras;
        }
    }

    private _cameras: PerspectiveCamera3D[];

    init()
    {
        const perspectiveCameras = this.cameras.map((v) => v._camera);
        this._camera = new ArrayCamera(perspectiveCameras);
        super.init();
    }

    destroy(): void
    {
        super.destroy();
    }
}
